<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	sendact.php
// Last Modification Time	:	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications	:
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
if (eregi("sendact.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}

if (!$USER_EMAL_VALID) {
  header ("Location:$SITE_URL/index.php");
	exit;
}

?>
<!--div:icerik -->
    <div id="icerik">
      <p>
<?php
if (isLogged()) echo $_LANG['login']['error1'];
elseif (empty($_POST)) {
  $action='index.php?page=sendact';
  if ($SITE_SEO) $action=$SITE_URL.'/sendact';
?>
<script type="text/javascript">
$(document).ready(function(){
  $("#activate").click(function(){
    $("#activate").val(" <?php echo $_LANG['login']['plswait']; ?> ");
    $("#activate").attr("disabled","disabled");
    var mail=$.trim($("#email").val());
    var pass=$.trim($("#pass").val());
    if (mail.length<6||mail.length>55) {
      alert("<?php echo $_LANG['login']['error2']; ?> ");
      $("#email").focus();
    }
    else if (pass.length<5||pass.length>15) {
      alert("<?php echo $_LANG['login']['error3']; ?> ");
      $("#pass").focus();
    }
    else $("#actForm").submit();
    $("#activate").val(" <?php echo $_LANG['sendact']['sendact']; ?> ");
    $("#activate").attr("disabled","");
  });
});
</script>
    <form method="post" action="<?php echo $action; ?>" id="actForm" class="box">
      <label><?php echo $_LANG['general']['email']; ?>: </label><input type="text" maxlength="55" name="email" id="email" /><br />
      <label><?php echo $_LANG['general']['pass']; ?>: </label><input type="password" maxlength="15" name="pass" id="pass" /><br />
      <label></label><input type="button" value=" <?php echo $_LANG['sendact']['sendact']; ?> " id="activate" class="input-submit" />
    </form><br />
<?php
    if (!$SITE_SEO) echo '<a href="index.php?page=lostpass" class="mlink">'.$_LANG['general']['lostpw'].'</a> ';
    else echo '<a href="'.$SITE_URL.'/lostpass" class="mlink">'.$_LANG['general']['lostpw'].'</a>';
}
else {
  $email=@$_POST['email'];
  $password=@$_POST['pass'];

  # check POST
  $valid=new Validation();
  $valid->inRange($email,55,6,$_LANG['login']['error2']);
  $valid->inRange($password,15,5,$_LANG['login']['error3']);
  $valid->checkEmail($email,$_LANG['general']['imail']);
  if ($valid->isError()) { # hugh, error
    $valid->listErrors();
  }
  else { #no error
    $email=$mysql->escape($email);
    $password=md5(strrev(md5($mysql->escape($password))));
    $code=md5(md5($pass.$date));

    $q=$mysql->query("select level,id from $USERS_TABLE where email='$email' and password='$password'");
    if ($mysql->numRows($q)==1) {
      if ($USER_EMAL_VALID) {
        $id=$mysql->result($q,'id');
        $level=$mysql->result($q,'level');

        if ($level==0) {
          $message=$ACTIVATION_MAIL_BODY.'<br /><a href="'.$SITE_URL.'/index.php?page=activate&id='.$id.'&email='.$email.'&code='.$code.'">'
          .$_LANG['sendact']['actmail']."$SITE_URL/index.php?page=activate&id=$lastID&email=$email&code=$code<br /><br />".$MAIL_SIGNATURE;

          $mail=sendMail($email,$SITE_CONTACT_MAIL,$ACTIVATION_MAIL_HEADER,$message);
          if ($mail) echo $_LANG['sendact']['actsent'];
          else echo $_LANG['sendact']['error1'].' '.$_LANG['errors']['error1'].': '.$SITE_ADMIN_MAIL;
        }
        else echo '<br />'.$_LANG['sendact']['error2'].'<br />';
      }
      else '<br />'.$_LANG['sendact']['error3'].'<br />';
    }
    else '<br />'.$_LANG['login']['error5'];
  } // else
}
?>
      </p>
    </div>
<!--//div:icerik -->